#include <iostream>
#include <vector>
using namespace std;

class segment_tree {
	vector<int> light;
	vector<bool> reverse;

	void lazy(int i, int n)
	{
		light[i] = n - light[i];
		reverse[i] = !reverse[i];
	}

	void down(int i, int ln, int rn)
	{
		if (reverse[i]) {
			lazy(i << 1, ln);
			lazy(i << 1 | 1, rn);
			reverse[i] = false;
		}
	}

	void up(int i)
	{
		light[i] = light[i << 1] + light[i << 1 | 1];
	}

    public:
	segment_tree(int n) : light(n << 2, 0), reverse(n << 2, false)
	{
	}

	void update(int jobl, int jobr, int l, int r, int i)
	{
		if (jobl <= l && r <= jobr) {
			lazy(i, r - l + 1);
		} else {
			int mid = (l + r) >> 1;
			down(i, mid - l + 1, r - mid);
			if (jobl <= mid) {
				update(jobl, jobr, l, mid, i << 1);
			}
			if (mid < jobr) {
				update(jobl, jobr, mid + 1, r, i << 1 | 1);
			}
			up(i);
		}
	}

	int query(int jobl, int jobr, int l, int r, int i)
	{
		if (jobl <= l && r <= jobr) {
			return light[i];
		}
		int mid = (l + r) >> 1;
		down(i, mid - l + 1, r - mid);
		int ans = 0;

		if (jobl <= mid) {
			ans += query(jobl, jobr, l, mid, i << 1);
		}
		if (mid < jobr) {
			ans += query(jobl, jobr, mid + 1, r, i << 1 | 1);
		}
		return ans;
	}
};

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, m;
	cin >> n >> m;
	segment_tree sgt(n);

	for (int i = 0, op, l, r; i < m; i++) {
		cin >> op >> l >> r;
		if (op == 0) {
			sgt.update(l, r, 1, n, 1);
		} else {
			cout << sgt.query(l, r, 1, n, 1) << '\n';
		}
	}

	return 0;
}